//
//  WSConst.h
//  WSBaseKit
//
//  Created by zhangcong on 2020/8/14.
//  Copyright © 2020 zhangcong. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "WSTool.h"

#ifdef __cplusplus
extern "C" {
#endif
    CGFloat getScreenWidth();
    
    CGFloat getScreenHeight();
    
    // 获取状态栏竖边高度
    CGFloat getStatusBarHeight();
    
    void setStatusBarHeight(CGFloat newH);
#ifdef __cplusplus
}
#endif



typedef void (^CompleteBlock)(id data);
typedef void (^SuccessBlock)(id data,NSString *msg, NSInteger code);
typedef void (^ProgressBlock)(NSDictionary * progressDict,CGFloat uploadProgress);
typedef void (^ErrorBlock)(NSError *error);
typedef void (^ErrorUrlBlock)(NSError *error , NSString * urlPath);

#define WScreenBounds [[UIScreen mainScreen] bounds]
#define WScreenSize WScreenBounds.size
#define WScreenWidth WScreenSize.width
#define WScreenHeight WScreenSize.height
#define WSCREEN_WIDTH_2          (WScreenWidth / 2)
#define WSCREEN_HEIGHT_2         (WScreenHeight / 2)
#define STATUSBAR_HEIGHT        getStatusBarHeight()

#define WSProtocol(instance, protocol, message) [(id<protocol>)(instance) message]


#define AppIsActive [UIApplication sharedApplication].applicationState == UIApplicationStateActive
#define iOSVersion      UIDevice.currentDevice.systemVersion.floatValue

#define IsIphone4                (SCREEN_HEIGHT == 480)
#define IsIphone5                (SCREEN_HEIGHT == 568)
#define IsIphone6                (SCREEN_HEIGHT == 667)
#define IsIphone6P               (SCREEN_HEIGHT == 736)
//#define IsIphoneX                (SCREEN_HEIGHT == 812)
#define IsIphoneX       (iOSVersion > 10.9 ? ([[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom > 0) : NO)

#define kStatusBarHeight            (IsIphoneX ? 44 : 20)
#define kNavbarHeight            (IsIphoneX ? 88 : 64)
#define kTabbarHeight            (IsIphoneX ? (49 + 34) : 49)
#define kBottomDistance             (IsIphoneX?34:0)

#define AssertMainThread        NSAssert([NSThread isMainThread], @"must be called from main thread");
#define RunAsyncOnMainThread(xxx)    dispatch_async(dispatch_get_main_queue(), ^{  \
xxx \
});
#define WS_SAFE_BLOCK(BlockName,...) ({ !BlockName ? nil : BlockName(__VA_ARGS__); })
#define WS(weakSelf)              __weak __typeof(&*self)weakSelf = self;
#define SS(strongSelf)            __strong typeof(weakSelf) strongSelf = weakSelf;


#define AppFont(font)             [UIFont systemFontOfSize:font]
#define AppBoldFont(font)         [UIFont boldSystemFontOfSize:font]

//string size计算
#define Dic(font)       @{NSFontAttributeName: AppFont(font)}
#define BoundIngRectWithText(text,SIZE,font) ([text boundingRectWithSize:SIZE options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:Dic(font) context:nil].size);
#define BoundIngRectWithAttributedString(attributedString,SIZE,font) ([attributedString boundingRectWithSize:SIZE options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil].size);

//默认图
#define kAppDefaultEmptyImageName        @"default_empty"
#define kAppDefaultEmptyImage           WSImage(kAppDefaultEmptyImageName)
#define kAppDefaultAvatar               WSImage(@"userDefaultIcon")

#define kAppDefaultImageNoInternet        @"defaultimage_nonet"
#define kAppDefaultImageNoLogin        @"defaultempty_nologin"

//App颜色
#define kAppBackgroundColor                 kUIColorWithRGB(0x14161F)
#define kAppMainColor                       kUIColorWithRGB(0x0BAAFE)
#define kAppHighlightedColor                kUIColorWithRGB(0xFFAC00)

//字体颜色
#define kAppMainTextColor                          kUIColorWithRGB(0x0BAAFE)
#define kAppSecondColor                        kUIColorWithRGB(0x665E41)


#define kAppNavColor                          kUIColorWithRGB(0x2d2f38)
#define kToolBarColor                         kAlphaColor(20.0,22.0,31.0,.3)

#define kColor(r,g,b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
#define kRandomColor kColor(arc4random()%256, arc4random()%256, arc4random()%256)



#define WSImage(imageName) [WSTool loadBundleImage:imageName]


#define kAction(number) (19901219 + number)


#import "UIColor+WS.h"
#import "UIView+WS.h"
#import "UIViewController+WSCategory.h"
#import "WSSafeMutableArray.h"

UIKIT_EXTERN NSString *const kAppNSErrorDomain;
UIKIT_EXTERN NSInteger const kAppNSErrorServer;
UIKIT_EXTERN NSInteger const kAppNSErrorDeviceIdError;
UIKIT_EXTERN NSInteger const kAppNSErrorSkillError;
UIKIT_EXTERN NSInteger const kAppNSErrorNoSkill;
UIKIT_EXTERN NSInteger const kAppNSErrorCodeRequestTooFast;
UIKIT_EXTERN NSInteger const kAppNSErrorNoLogin;
UIKIT_EXTERN NSInteger const kAppNSErrorTokenCode;
UIKIT_EXTERN NSInteger const kAppNSErrorJsonCode;
UIKIT_EXTERN NSInteger const kAppNSErrorTokenExpired;
UIKIT_EXTERN NSInteger const kAppNSErrorCheckDataCode;
UIKIT_EXTERN NSInteger const kAppNSErrorLoginCode;
UIKIT_EXTERN NSInteger const kAppNSErrorCodeParameterError;         //参数错误
UIKIT_EXTERN NSInteger const kAppNSErrorForbidComment;
UIKIT_EXTERN NSInteger const kAppNSErrorLoginCodeNoAccount;
UIKIT_EXTERN NSInteger const kAppNSErrorLoginCodeErrorPwd;
UIKIT_EXTERN NSInteger const kAppNSErrorLoginCodeLimited;
UIKIT_EXTERN NSInteger const kAppNSErrorAlreadyRegister;
UIKIT_EXTERN NSInteger const kAppNSErrorCodeExpired;
UIKIT_EXTERN NSInteger const kAppNSErrorRegisterFail;
UIKIT_EXTERN NSInteger const kAppNSErrorCodeError;
UIKIT_EXTERN NSInteger const kAppNSErrorCodeUnKnow;
UIKIT_EXTERN NSInteger const kAppNSErrorCode500;
